import React,{ Component } from 'react'
import { Upload, Button, Icon,Modal,message } from 'antd';
import { refresh } from '../../../actions/disk'
import * as name from '../../../config/constant'

class UploadModal extends Component {
  sprops = {
    action: name._API+'/disk?action=upload&dir='+this.props.parent+'&token='+this.props.token,
    headers: {
      'X-Requested-With':null
    },
    onChange(info){
      const status = info.file.status
      if (status === 'done') {
        message.success(info.file.name+'上传成功!')
      }
      if (status === 'error') {
        message.error(info.file.name+'上传失败!')
      }
    }
  };

  onEnd = () => {
    const { dispatch,parent } = this.props
    dispatch(refresh(dispatch,parent))
    this.props.ok()
  }

  render(){
    this.sprops.action = name._API+'/disk?action=upload&dir='+this.props.parent+'&token='+this.props.token
    return (
      <Modal
      title={'文件上传'}
      visible={this.props.visible}
      onCancel={this.onEnd}
      width={400}
      footer={null}
      >
      <Upload {...this.sprops}>
      <Button>
      <Icon type="upload" /> 点击上传
      </Button>
      </Upload>
      </Modal>
    )
  }
}

export default UploadModal
